package com.dhcc.sds.standard.function;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.dhcc.cdc.busi.dao.CdcBsEmrStructMapper;
import com.dhcc.cdc.busi.dao.CdcEpisodeMapper;
import com.dhcc.cdc.busi.dao.CdcSurgeryMapper;
import com.dhcc.cdc.busi.entity.*;
import com.dhcc.cdc.busi.service.*;
import com.dhcc.cdc.sys.cache.config.CdcConfigCache;
import com.dhcc.cdc.sys.dao.DictionaryMapper;
import com.dhcc.cdc.sys.entity.DictionaryEntity;
import com.dhcc.cdc.sys.service.IDictionaryService;
import com.dhcc.core.framework.util.CommonUtil;
import com.dhcc.core.framework.util.DateUtil;
import com.dhcc.core.framework.util.ObjectUtil;
import com.dhcc.core.framework.util.SpringContextHolder;
import com.dhcc.sdc.base.entity.ContraindicationEntity;
import com.dhcc.sdc.base.service.IContraindicationService;
import com.dhcc.sdc.busi.entity.SdcBusiContraindicationEntity;
import com.dhcc.sdc.busi.service.ISdcBusiContraindicationService;
import com.dhcc.sdc.busi.service.ISdcBusiEvaluationService;
import com.dhcc.sds.base.cache.formitemdic.FormItemDicCache;
import com.dhcc.sds.base.cache.qcentity.QcEntityCache;
import com.dhcc.sds.base.dao.SdsFunctionMapper;
import com.dhcc.sds.base.entity.SdsQcentityEntity;
import com.dhcc.sds.base.entity.SdsQcentityRuleEntity;
import com.dhcc.sds.base.entity.SdsQcfitemDicEntity;
import com.dhcc.sds.base.service.ISdsQcentityRuleService;
import com.dhcc.sds.busi.entity.SdsQcincaseOperlogEntity;
import com.dhcc.sds.busi.service.ISdsQcincaseOperlogService;
import com.dhcc.sds.standard.dao.*;
import com.dhcc.sds.standard.entity.SdsStandDicEntity;
import com.dhcc.sds.standard.entity.SdsStandDicMatchParamEntity;
import com.dhcc.sds.standard.entity.SdsStandSourceEntity;
import com.dhcc.sds.standard.service.ISdsStandDicService;
import com.dhcc.sds.util.NLPUtil;
import org.apache.commons.lang.text.StrSubstitutor;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.io.IOException;
import java.text.DecimalFormat;
import java.util.*;

/**
 * @Description: 规则库取值函数类
 * @author:zhangdc
 * @date:2023年05月26日14:02:49
 * @Copyright: (c) DHCC All rights reserved.
 */
@Service("getRuleValueSrv")
public class GetRuleValueSrv {

    static SdsStandSourceMapper sdsStandSourceMapper = SpringContextHolder.getBean("sdsStandSourceMapper");
    static CdcEpisodeMapper cdcEpisodeMapper = SpringContextHolder.getBean("cdcEpisodeMapper");
    static ICdcDictionaryService cdcDictionaryService = SpringContextHolder.getBean("cdcDictionaryService");
    static ICdcTransferService cdcTransferService = SpringContextHolder.getBean("cdcTransferService");
    static ICdcLocationService cdcLocationService = SpringContextHolder.getBean("cdcLocationService");
    static ICdcOrdexecService cdcOrdexecService = SpringContextHolder.getBean("cdcOrdexecService");
    static ICdcOrdmastService cdcOrdmastService = SpringContextHolder.getBean("cdcOrdmastService");
    static SdsFunctionMapper sdsFunctionMapper = SpringContextHolder.getBean("sdsFunctionMapper");
    static  ISdcBusiEvaluationService sdcBusiEvaluationService = SpringContextHolder.getBean("sdcBusiEvaluationService");
    static  SdsStandDicMapper sdsStandDicMapper = SpringContextHolder.getBean("sdsStandDicMapper");
    static  DictionaryMapper dictionaryMapper = SpringContextHolder.getBean("dictionaryMapper");
    static  CdcSurgeryMapper cdcSurgeryMapper = SpringContextHolder.getBean("cdcSurgeryMapper");
    static  SdsStandDicMatchMapper sdsStandDicMatchMapper = SpringContextHolder.getBean("sdsStandDicMatchMapper");
    static  SdsStandDicMatchParamMapper sdsStandDicMatchParamMapper = SpringContextHolder.getBean("sdsStandDicMatchParamMapper");
    static  IDictionaryService dictionaryService = SpringContextHolder.getBean("dictionaryService");
    static  CdcBsEmrStructMapper cdcBsEmrStructMapper = SpringContextHolder.getBean("cdcBsEmrStructMapper");
    static  IContraindicationService baseContraindicationService = SpringContextHolder.getBean("contraindicationService");
    static  ISdcBusiContraindicationService sdcBusiContraindicationService = SpringContextHolder.getBean("sdcBusiContraindicationService");
    static  ISdsQcincaseOperlogService sdsQcincaseOperlogService = SpringContextHolder.getBean("sdsQcincaseOperlogService");
    static  ISdsQcentityRuleService sdsQcentityRuleService = SpringContextHolder.getBean("sdsQcentityRuleService");
    static ISdsStandDicService sdsStandDicService = SpringContextHolder.getBean("sdsStandDicService");

    /**
     * 获取病人HIS数据-就诊信息
     */
    public Object Episode(Long episodeId, Long datasourceId, Integer currentTime, Long dicId, Long valueTime,String orderSql){
        String resultVal = "";
        if (StringUtils.isEmpty(datasourceId)){
            if (1 == currentTime){
                resultVal = DateUtil.getTime();
            }
        }else {
            SdsStandSourceEntity source = sdsStandSourceMapper.selectById(datasourceId);
            if (!StringUtils.isEmpty(source)){
                String sourceCode = source.getSourceCode();
                switch (sourceCode){
                    case "OEDateT":
                        //到达本院急诊或者门诊日期时间
                        CdcEpisodeEntity cdcEpisodeEntity = cdcEpisodeMapper.selectById(episodeId);
                        if (!StringUtils.isEmpty(cdcEpisodeEntity)){
                            //住院次数
                            Integer admNums = cdcEpisodeEntity.getAdmNums();
                            //患者主索引
                            String patientCode = cdcEpisodeEntity.getPatientCode();
                            if (!StringUtils.isEmpty(admNums) && (admNums > 1)){
                                List<CdcEpisodeEntity> CdcEpisodeEntitys = cdcEpisodeMapper.selectByPatientCode(patientCode);
                                //就诊类型:E急诊
                                CdcDictionaryEntity admType1 = cdcDictionaryService.queryByTypeCodeAndCode("PatData", "bus_adm_type", "E");
                                //就诊类型:O门诊
                                CdcDictionaryEntity admType2 = cdcDictionaryService.queryByTypeCodeAndCode("PatData", "bus_adm_type", "O");
                                for (CdcEpisodeEntity cdcEpisodeEntity1 : CdcEpisodeEntitys){
                                    //就诊类型过滤(只需要门诊和急诊的)
                                    if (Objects.equals(admType1.getId(), cdcEpisodeEntity1.getBusAdmTypeId()) || Objects.equals(admType2.getId(), cdcEpisodeEntity1.getBusAdmTypeId())){
                                        Long h = com.dhcc.sds.util.DateUtil.getDateCompare(cdcEpisodeEntity.getAdmDate(), cdcEpisodeEntity1.getAdmDate(), "h");
                                        if (h < 24) {
                                            resultVal = DateUtil.format(cdcEpisodeEntity1.getAdmDate(), "yyyy-MM-dd HH:mm:ss");
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        break;
                    case "InDeptDate":
                        //入住某科室日期时间
                        if (!StringUtils.isEmpty(dicId)){
                            //先查询就诊科室
                            Map<String, String> mapParam = handleDicMatchParam(dicId, 3);
                            CdcEpisodeEntity admLocInfo = sdsFunctionMapper.selectAdmLocInfoByParam(episodeId, mapParam);
                            if (!StringUtils.isEmpty(admLocInfo)){
                                resultVal = DateUtil.format(admLocInfo.getAdmDate(), "yyyy-MM-dd HH:mm:ss");
                            }else {
                                //再查询转科记录
                                //转科不支持&参数连接和排除参数
                                List<CdcTransferEntity>  cdcTransferEntities = sdsFunctionMapper.selectTransferLocInfoByParam(episodeId, mapParam);
                                if (!StringUtils.isEmpty(cdcTransferEntities)){
                                    resultVal = DateUtil.format(cdcTransferEntities.get(0).getTranDate(), "yyyy-MM-dd HH:mm:ss");
                                }
                            }
                        }
                        break;
                    case "OutDeptDate":
                        //离开某科室日期时间
                        if (!StringUtils.isEmpty(dicId)){
                            Map<String, String> mapParam = handleDicMatchParam(dicId, 3);
                            List<CdcTransferEntity>  cdcTransferEntities = sdsFunctionMapper.selectTransferLocInfoByParam(episodeId, mapParam);
                            if (!StringUtils.isEmpty(cdcTransferEntities)){
                                resultVal = DateUtil.format(cdcTransferEntities.get(0).getFromDate(), "yyyy-MM-dd HH:mm:ss");
                            }
                        }
                        break;
                    case "InHosTrans":
                        //到院交通工具,默认私家车
                        resultVal = "私家车";
                        Wrapper<CdcOrdexecEntity> ordexecEntityWrapper = new EntityWrapper<>();
                        ordexecEntityWrapper.eq("episode_id", episodeId).eq("is_active", 1);
                        List<CdcOrdexecEntity> cdcOrdexecEntities = cdcOrdexecService.selectList(ordexecEntityWrapper);
                        for (CdcOrdexecEntity cdcOrdexecEntity : cdcOrdexecEntities){
                            CdcOrdmastEntity ordmastEntity = cdcOrdmastService.selectById(cdcOrdexecEntity.getOrderMastId());
                            if (!StringUtils.isEmpty(ordmastEntity)) {
                                if (ordmastEntity.getDescription().contains("救护车")) {
                                    resultVal = "救护车";
                                    break;
                                }
                            }
                        }
                        break;
                    default:
                        // 通过就诊号获取患者就诊信息
                        Map<String, Object> episodeInfo = sdsFunctionMapper.getPatientInfo(episodeId);
                        resultVal = ObjectUtil.toString(episodeInfo.get(sourceCode));
                        if (CommonUtil.equals(resultVal, "男")) {
                            resultVal = "M";
                        } else if (CommonUtil.equals(resultVal, "女")) {
                            resultVal = "F";
                        }
                        //对科室处理，去掉短横线和括号
                        if (CommonUtil.equals(sourceCode, "admloc")) {
                            if (CommonUtil.contains(resultVal, "-")) {
                                resultVal = resultVal.split("-")[1];
                            }
                            resultVal = resultVal.replace("(", "");
                            resultVal = resultVal.replace(")", "");
                            resultVal = resultVal.replace("/", "");
                        }
                        break;
                }
            }
        }
        return resultVal;
    }

    /**
     * 获取病人HIS数据-医嘱信息
     */
    public Object Ordexec(Long episodeId, Long datasourceId, Integer currentTime, Long dicId, Long valueTime,String orderSql){
        Object resultVal = "";
        if (StringUtils.isEmpty(datasourceId)){
            if (1 == currentTime){
                resultVal = DateUtil.getTime();
            }
        }else {
            SdsStandSourceEntity source = sdsStandSourceMapper.selectById(datasourceId);
            if (!StringUtils.isEmpty(source)){
                String sourceCode = source.getSourceCode();
                String sqlStr = "";
                if(!StringUtils.isEmpty(valueTime)){
                    sqlStr = this.calcGetExecTiming(episodeId, valueTime);
                }
                if (!StringUtils.isEmpty(dicId)){
                    List<Map<String, Object>> list = new ArrayList<>();
                    // 查询标准项关联医嘱
                    //List<Long> ordMastList1 = sdsStandDicMatchMapper.selectMatchOrderIds(param);
                    List<Long> ordMastList1 = sdsStandDicMatchMapper.selectMatchOrderId(dicId);
                    if (!ordMastList1.isEmpty()){
                        list = sdsFunctionMapper.selectOrdExec(episodeId, null, ordMastList1, sqlStr);
                    }
                    if (list.isEmpty()){
                        //查找子节点
                        List<Long> dicChildrenIds = sdsStandDicService.getRootChildren(dicId);
                        for (Long dicChildrenId : dicChildrenIds){
                            List<Long> ordMastList2 = sdsStandDicMatchMapper.selectMatchOrderId(dicChildrenId);
                            if (!ordMastList2.isEmpty()){
                                list = sdsFunctionMapper.selectOrdExec(episodeId, null, ordMastList2, sqlStr);
                                if (!list.isEmpty()){
                                    break;
                                }
                            }
                        }
                    }
                    if ("Quantity".equals(sourceCode)){
                        resultVal = list.size();
                    }else {
                        for (Map<String, Object> map : list) {
                            if (CommonUtil.isNotEmpty(map.get(sourceCode))) {
                                resultVal = map.get(sourceCode);
                                break;
                            }
                        }
                    }
                }
            }
        }
        return resultVal;
    }

    /**
     * 获获取病人HIS数据-诊断信息
     */
    public Object Diagnosis(Long episodeId, Long datasourceId, Integer currentTime, Long dicId, Long valueTime,String orderSql){
        Object resultVal = "";
        if (StringUtils.isEmpty(datasourceId)){
            if (1 == currentTime){
                resultVal = DateUtil.getTime();
            }
        }else{
            SdsStandSourceEntity source = sdsStandSourceMapper.selectById(datasourceId);
            if (!StringUtils.isEmpty(source)){
                String sourceCode = source.getSourceCode();
                CdcDictionaryEntity diagSource = new CdcDictionaryEntity();
                if ("M4DICD10".equals(sourceCode) || "M6DICD10".equals(sourceCode)){
                    //上报：诊断来源-编目信息
                     diagSource = dictionaryService.getMatchCtDic("SDS", "SDMatchCdcDic", "F");
                }
                if ("Quantity".equals(sourceCode) || "DiagDate".equals(sourceCode)){
                    //质控：诊断来源-临床
                     diagSource = dictionaryService.getMatchCtDic("SDS", "SDMatchCdcDic", "C");
                }
                List<CdcDiagnosisEntity> diagnosisEntities = new ArrayList<>();
                if (!StringUtils.isEmpty(dicId)){
                    //配有标准字典根据对照参数取值
                    //有子节点需取所有子节点的值
                    /*List<Long> dicIds = sdsStandDicService.getRootChildren(dicId);
                    for (Long id : dicIds){
                        Map<String, String> mapParam = handleDicMatchParam(id, 2);
                        List<CdcDiagnosisEntity> cdcDiagnosisEntities = sdsFunctionMapper.selectDiagnosisInfoByParam(episodeId, diagSource.getId(), mapParam);
                        diagnosisEntities.addAll(cdcDiagnosisEntities);
                    }*/
                    Map<String, String> mapParam = handleDicMatchParam(dicId, 2);
                    List<CdcDiagnosisEntity> cdcDiagnosisEntities = sdsFunctionMapper.selectDiagnosisInfoByParam(episodeId, diagSource.getId(), mapParam);
                    if (cdcDiagnosisEntities.isEmpty()){
                        //有子节点需取所有子节点的值
                        List<Long> dicIds = sdsStandDicService.getRootChildren(dicId);
                        for (Long id : dicIds){
                            Map<String, String> mapParamChildren = handleDicMatchParam(id, 2);
                            List<CdcDiagnosisEntity> cdcDiagnosisChildrenEntities = sdsFunctionMapper.selectDiagnosisInfoByParam(episodeId, diagSource.getId(), mapParamChildren);
                            if (!cdcDiagnosisChildrenEntities.isEmpty()){
                                diagnosisEntities.addAll(cdcDiagnosisChildrenEntities);
                                break;
                            }
                        }
                    }else {
                        diagnosisEntities.addAll(cdcDiagnosisEntities);
                    }
                }else {
                    //只配置数据源
                    diagnosisEntities = sdsFunctionMapper.selectDiagnosisInfoByParam(episodeId, diagSource.getId(), new HashMap<>());
                }
                if ("Quantity".equals(sourceCode)){
                    resultVal = diagnosisEntities.size();
                }else if ("M4DICD10".equals(sourceCode) || "M6DICD10".equals(sourceCode)){
                    String resultStr = "";
                    for (CdcDiagnosisEntity cdcDiagnosisEntity : diagnosisEntities){
                        String icd10 = cdcDiagnosisEntity.getIcd10();
                        if (Objects.equals(1, cdcDiagnosisEntity.getIsMain())){
                            //主诊断
                            if (Objects.equals("M4DICD10", sourceCode)){
                                //主要诊断ICD-10四位亚目编码与名称
                                if (icd10.length() > 4) {
                                    resultStr = icd10.substring(0, 5);
                                }
                                String lastChar = resultStr.substring(resultStr.length() - 1);
                                if ("x".equals(lastChar)) {
                                    resultStr = resultStr.substring(0, resultStr.length() - 1);
                                }
                                lastChar = resultStr.substring(resultStr.length() - 1);
                                if (".".equals(lastChar)) {
                                    resultStr = resultStr.substring(0, resultStr.length() - 1);
                                }
                            }else if (Objects.equals("M6DICD10", sourceCode)){
                                //主要诊断ICD-10六位临床扩展编码与名称
                                String substring = "";
                                if (icd10.length() >= 8) {
                                    substring = icd10.substring(7, 8);
                                }
                                if (Objects.equals("x", substring) && icd10.length() >= 11) {
                                    resultStr = icd10.substring(0, 11);
                                } else if (!Objects.equals("x", substring) && icd10.length() >= 7) {
                                    resultStr = icd10.substring(0, 7);
                                }
                            }
                        }
                        if (!StringUtils.isEmpty(resultStr)) {
                            resultVal = resultStr;
                            break;
                        }
                    }
                }else if ("DiagDate".equals(sourceCode)){
                    // 诊断时间
                    for (CdcDiagnosisEntity cdcDiagnosisEntity : diagnosisEntities){
                        Date diagDate = cdcDiagnosisEntity.getDiagDate();
                        if (!StringUtils.isEmpty(diagDate)){
                            resultVal = DateUtil.getTime(diagDate);
                            break;
                        }
                    }
                }

            }
        }
        return resultVal;
    }

    /**
     * 获取病人电子病历-住院病程信息
     * 返回emrID
     */
    public Object EmrInfo(Long episodeId, Long datasourceId, Integer currentTime, Long dicId, Long valueTime,String orderSql){
        Object resultVal = "";
        if (StringUtils.isEmpty(datasourceId)){
            if (1 == currentTime){
                resultVal = DateUtil.getTime();
            }
        }else{
            SdsStandSourceEntity source = sdsStandSourceMapper.selectById(datasourceId);
            if (!StringUtils.isEmpty(source)){
                String sourceCode = source.getSourceCode();
                if (!StringUtils.isEmpty(dicId)){
                    SdsStandDicEntity dicEntity = sdsStandDicMapper.selectById(dicId);
                    //查找关联病历子标题
                    Map<String, Object> param = new HashMap<String, Object>();
                    //查找标准字典的父级：症状、体征、现病史。。。
                    Long parentId = dicEntity.getParentId();
                    // 查询标准项所有关联医嘱
                    param.put("dicId", parentId);
                    List<String> subTitles = sdsStandDicMatchMapper.selectEmrSubTitle(param);
                    if (!subTitles.isEmpty()){
                        List<CdcBsEmrStructEntity> emrStructs = sdsFunctionMapper.selectEmrStructInfoByParam(episodeId, subTitles);
                        if (null != emrStructs && emrStructs.size() > 0){
                            //查找标准字典关联的对照参数
                            List<SdsStandDicMatchParamEntity> dicMatchParamEntities = sdsStandDicMatchParamMapper.selectList(new EntityWrapper<SdsStandDicMatchParamEntity>()
                                    .eq("dic_id", dicId));
                            if (null != dicMatchParamEntities && dicMatchParamEntities.size() > 0){
                                c:for (CdcBsEmrStructEntity emrStruct : emrStructs){
                                    JSONArray jsonArray = JSONArray.parseArray(emrStruct.getEmrNlpResult());
                                    if (jsonArray.size() > 0){
                                        a:for (int i = 0;i < jsonArray.size();i ++){
                                            JSONObject jsonObject = jsonArray.getJSONObject(i);
                                            b:for (SdsStandDicMatchParamEntity sdsStandDicMatchParam : dicMatchParamEntities){
                                                //目前没有排除
                                                String compareContent = sdsStandDicMatchParam.getCompareContent();
                                                if (compareContent.contains(",")){
                                                    //eg:皮肤瘙痒#level:加重,day_time:夜间
                                                    //同时满足
                                                    String[] split = compareContent.split(",");
                                                    for (String s : split){
                                                        if (s.contains("#")){
                                                            String[] split1 = s.split("#");
                                                            String name = split1[0];
                                                            String nlpValue = split1[1];
                                                            if (!name.equals(jsonObject.get("name"))){
                                                                continue b;
                                                            }
                                                            if (nlpValue.contains(":")){
                                                                String[] split2 = nlpValue.split(":");
                                                                if (!split2[1].equals(jsonObject.get(split2[0]))){
                                                                    continue b;
                                                                }
                                                            }
                                                        }else {
                                                            if (s.contains(":")){
                                                                String[] split1 = s.split(":");
                                                                if (!split1[1].equals(jsonObject.get(split1[0]))){
                                                                    continue b;
                                                                }
                                                            }
                                                        }
                                                    }
                                                    //都满足:返回EmrId，退出循环
                                                    //resultVal = emrStruct.getEmrId();
                                                    //都满足:返回true，退出循环
                                                    resultVal = true;
                                                    break c;
                                                }else {
                                                    //eg:呼吸困难#level:加重
                                                    if (compareContent.contains("#")){
                                                        String[] split = compareContent.split("#");
                                                        String name = split[0];
                                                        String nlpValue = split[1];
                                                        if (!name.equals(jsonObject.get("name"))){
                                                            continue b;
                                                        }
                                                        if (nlpValue.contains(":")){
                                                            String[] split2 = nlpValue.split(":");
                                                            if (!split2[1].equals(jsonObject.get(split2[0]))){
                                                                continue b;
                                                            }
                                                        }
                                                        //满足一个:返回EmrId，退出循环
                                                        //resultVal = emrStruct.getEmrId();
                                                        //满足一个:返回true，退出循环
                                                        resultVal = true;
                                                        break c;
                                                    }else {
                                                        //eg:level:加重
                                                        if (compareContent.contains(":")){
                                                            String[] split = compareContent.split(":");
                                                            if (!split[1].equals(jsonObject.get(split[0]))){
                                                                continue b;
                                                            }
                                                            //满足一个:返回EmrId，退出循环
                                                            //resultVal = emrStruct.getEmrId();
                                                            //满足一个:返回true，退出循环
                                                            resultVal = true;
                                                            break c;
                                                        }else {
                                                            //eg:发热
                                                            if (!compareContent.equals(jsonObject.get("name"))){
                                                                continue b;
                                                            }
                                                            //满足一个:返回EmrId，退出循环
                                                            //resultVal = emrStruct.getEmrId();
                                                            //满足一个:返回true，退出循环
                                                            resultVal = true;
                                                            break c;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        return resultVal;
    }

    /**
     * 获取病人电子病历-住病案首页基本信息
     */
    public Object EprBaseInfo(Long episodeId, Long datasourceId, Integer currentTime, Long dicId, Long valueTime,String orderSql){
        Object resultVal = "";
        if (StringUtils.isEmpty(datasourceId)){
            if (1 == currentTime){
                resultVal = DateUtil.getTime();
            }
        }else {
            SdsStandSourceEntity source = sdsStandSourceMapper.selectById(datasourceId);
            if (!StringUtils.isEmpty(source)){
                String sourceCode = source.getSourceCode();
                resultVal = sdsFunctionMapper.selectEprBaseInfo(episodeId, sourceCode);
            }
        }
        return resultVal;
    }

    /**
     * 获取病人电子病历-住病案首页费用信息
     */
    public Object EprFeeInfo(Long episodeId, Long datasourceId, Integer currentTime, Long dicId, Long valueTime,String orderSql){
        Object resultVal = "";
        if (StringUtils.isEmpty(datasourceId)){
            if (1 == currentTime){
                resultVal = DateUtil.getTime();
            }
        }else {
            SdsStandSourceEntity source = sdsStandSourceMapper.selectById(datasourceId);
            if (!StringUtils.isEmpty(source)){
                String sourceCode = source.getSourceCode();
                Map param = new HashMap<>();
                param.put("episodeId", episodeId);
                Map<Object, Object> feeMap = sdsFunctionMapper.getFeeByType(param);
                if (CommonUtil.isNotEmpty(feeMap)){
                    if (CommonUtil.isNotEmpty(feeMap.get(sourceCode))){
                        String  feeValue= feeMap.get(sourceCode).toString();
                        //处理精度，小数点后两位
                        DecimalFormat df = new DecimalFormat("0.00");
                        resultVal = df.format(Float.parseFloat(feeValue));
                    }
                }

            }
        }
        return resultVal;
    }

    /**
     * 获取病人电子病历-住病案首页手术信息
     */
    public Object EmrOperInfo(Long episodeId, Long datasourceId, Integer currentTime, Long dicId, Long valueTime,String orderSql){
        Object resultVal = "";
        if (StringUtils.isEmpty(datasourceId)){
            if (1 == currentTime){
                resultVal = DateUtil.getTime();
            }
        }else {
            SdsStandSourceEntity source = sdsStandSourceMapper.selectById(datasourceId);
            if (!StringUtils.isEmpty(source)){
                String sourceCode = source.getSourceCode();
                //数据来源:病案编目
                //根据数据中心字典对照获取病案编目
                CdcDictionaryEntity surgSource = dictionaryService.getMatchCtDic("SDS", "SDMatchCdcDic", "F1");
                List<CdcSurgeryEntity> surgeryEntities = new ArrayList<>();
                if (!StringUtils.isEmpty(dicId)){
                    //配有标准字典根据对照参数取值
                    Map<String, String> mapParam = handleDicMatchParam(dicId, 1);
                    //查询病案编目手术信息
                    surgeryEntities = sdsFunctionMapper.selectSurgeryInfoByParam(episodeId, surgSource.getId(), mapParam);
                }else {
                    //只配置数据源
                    surgeryEntities = sdsFunctionMapper.selectSurgeryInfoByParam(episodeId, surgSource.getId(), null);
                }
                String resultStr = "";
                if (null != surgeryEntities && surgeryEntities.size() > 0){
                    //获取编目手术 (第一手术默认为主手术)
                    CdcSurgeryEntity cdcSurgeryEntity = surgeryEntities.get(0);
                    String code = cdcSurgeryEntity.getCode();
                    if (Objects.equals("M4OCM3", sourceCode)) {
                        //主要手术操作栏中提取ICD-9-CM-3四位亚目编码与名称
                        if (code.length() > 4) {
                            resultStr = code.substring(0, 5);
                        }
                        String lastChar = resultStr.substring(resultStr.length() - 1);
                        if ("x".equals(lastChar)) {
                            resultStr = resultStr.substring(0, resultStr.length() - 1);
                        }
                        lastChar = resultStr.substring(resultStr.length() - 1);
                        if (".".equals(lastChar)) {
                            resultStr = resultStr.substring(0, resultStr.length() - 1);
                        }
                    } else if (Objects.equals("M6OCM3", sourceCode)) {
                        //主要手术操作栏中提取ICD-9-CM-3六位临床扩展编码与名称
                        String substring = "";
                        if (code.length() >= 8) {
                            substring = code.substring(7, 8);
                        }
                        if (Objects.equals("x", substring) && code.length() >= 11) {
                            resultStr = code.substring(0, 11);
                        } else if (code.length() >= 7) {
                            resultStr = code.substring(0, 7);
                        }
                    } else {
                        if (CommonUtil.equals("startDate", sourceCode)) {
                            resultStr = DateUtil.getTime(cdcSurgeryEntity.getStartDate());
                        } else if (CommonUtil.equals("endDate", sourceCode)) {
                            resultStr = DateUtil.getTime(cdcSurgeryEntity.getEndDate());
                        } else if (CommonUtil.equals("LoseBlood", sourceCode)) {
                            resultStr = cdcSurgeryEntity.getBloodLose();
                        } else if (CommonUtil.equals("healType", sourceCode)) {
                            CdcDictionaryEntity cdcDictionaryEntity = cdcDictionaryService.selectById(cdcSurgeryEntity.getBusSurgHealId());
                            if (!StringUtils.isEmpty(cdcDictionaryEntity)) {
                                resultStr = cdcDictionaryEntity.getDescription();
                            }
                        } else if (CommonUtil.equals("GotBlood", sourceCode)) {
                            resultStr = cdcSurgeryEntity.getBloodGet();
                        } else if (CommonUtil.equals("inciLevel", sourceCode)) {
                            CdcDictionaryEntity cdcDictionaryEntity = cdcDictionaryService.selectById(cdcSurgeryEntity.getBusSurgInciId());
                            if (!StringUtils.isEmpty(cdcDictionaryEntity)) {
                                resultStr = cdcDictionaryEntity.getDescription();
                            }
                        } else if (CommonUtil.equals("inciCount", sourceCode)) {
                            resultStr = cdcSurgeryEntity.getInciCount().toString();
                        } else if (CommonUtil.equals("anesType", sourceCode)) {
                            CdcDictionaryEntity cdcDictionaryEntity = cdcDictionaryService.selectById(cdcSurgeryEntity.getBusSurgAnesId());
                            if (!StringUtils.isEmpty(cdcDictionaryEntity)) {
                                resultStr = cdcDictionaryEntity.getDescription();
                            }
                        }
                    }
                }
                if (CommonUtil.isNotEmpty(resultStr)){
                    resultVal = resultStr;
                }
            }
        }
        return resultVal;
    }

    /**
     * 获取病人检查系统信息
     */
    public Object Ris(Long episodeId, Long datasourceId, Integer currentTime, Long dicId, Long valueTime,String orderSql){
        Object resultVal = "";
        if (StringUtils.isEmpty(datasourceId)){
            if (1 == currentTime){
                resultVal = DateUtil.getTime();
            }
        }else {
            SdsStandSourceEntity source = sdsStandSourceMapper.selectById(datasourceId);
            if (!StringUtils.isEmpty(source)){
                String sourceCode = source.getSourceCode();
                if (!StringUtils.isEmpty(dicId)){
                    String sqlStr = "";
                    if(!StringUtils.isEmpty(valueTime)){
                        sqlStr = this.calcGetExecTiming(episodeId, valueTime);
                    }
                    //查找标准字典关联的对照参数
                    List<SdsStandDicMatchParamEntity> dicMatchParamEntities = sdsStandDicMatchParamMapper.selectList(new EntityWrapper<SdsStandDicMatchParamEntity>()
                            .eq("dic_id", dicId));
                    if (null != dicMatchParamEntities && dicMatchParamEntities.size() > 0){
                        //查询患者所有的检查报告
                        List<Map<String, Object>> exams = sdsFunctionMapper.selectExaminate(episodeId, null, null, sqlStr);
                        if (null != exams && exams.size() > 0){
                            String nlpUrl = CdcConfigCache.me().getValueByKey("SDS", "SDAnalysisServer");
                            if ("checkResult".equals(sourceCode)){
                                //检查结果
                                String content = "";
                                for (Map<String, Object> map : exams){
                                    if (CommonUtil.isNotEmpty(map.get("examDesc"))){
                                        //检查所见
                                        content += map.get("examDesc") + "。";
                                    }
                                    if (CommonUtil.isNotEmpty(map.get("resultDesc"))){
                                        //诊断意见
                                        content += map.get("resultDesc") + "。";
                                    }
                                }
                                String NLPValue = (String) NLPUtil.parse(nlpUrl, content);
                                JSONArray jsonArray = JSONArray.parseArray(NLPValue);
                                if (jsonArray.size() > 0){
                                    a:for (int i = 0;i < jsonArray.size();i ++){
                                        JSONObject jsonObject = jsonArray.getJSONObject(i);
                                        b:for (SdsStandDicMatchParamEntity sdsStandDicMatchParam : dicMatchParamEntities){
                                            //目前没有排除
                                            String compareContent = sdsStandDicMatchParam.getCompareContent();
                                            if (compareContent.contains(",")){
                                                //eg:皮肤瘙痒#level:加重,day_time:夜间
                                                //同时满足
                                                String[] split = compareContent.split(",");
                                                for (String s : split){
                                                    if (s.contains("#")){
                                                        String[] split1 = s.split("#");
                                                        String name = split1[0];
                                                        String nlpValue = split1[1];
                                                        if (!name.equals(jsonObject.get("name"))){
                                                            continue b;
                                                        }
                                                        if (nlpValue.contains(":")){
                                                            String[] split2 = nlpValue.split(":");
                                                            if (!split2[1].equals(jsonObject.get(split2[0]))){
                                                                continue b;
                                                            }
                                                        }
                                                    }else {
                                                        if (s.contains(":")){
                                                            String[] split1 = s.split(":");
                                                            if (!split1[1].equals(jsonObject.get(split1[0]))){
                                                                continue b;
                                                            }
                                                        }
                                                    }
                                                }
                                                //都满足:返回true，退出循环
                                                resultVal = true;
                                                break a;
                                            }else {
                                                //eg:呼吸困难#level:加重
                                                if (compareContent.contains("#")){
                                                    String[] split = compareContent.split("#");
                                                    String name = split[0];
                                                    String nlpValue = split[1];
                                                    if (!name.equals(jsonObject.get("name"))){
                                                        continue b;
                                                    }
                                                    if (nlpValue.contains(":")){
                                                        String[] split2 = nlpValue.split(":");
                                                        if (!split2[1].equals(jsonObject.get(split2[0]))){
                                                            continue b;
                                                        }
                                                    }
                                                    //满足一个:返回true，退出循环
                                                    resultVal = true;
                                                    break a;
                                                }else {
                                                    //eg:level:加重
                                                    if (compareContent.contains(":")){
                                                        String[] split = compareContent.split(":");
                                                        if (!split[1].equals(jsonObject.get(split[0]))){
                                                            continue b;
                                                        }
                                                        //满足一个:返回true，退出循环
                                                        resultVal = true;
                                                        break a;
                                                    }else {
                                                        //eg:发热
                                                        if (!compareContent.equals(jsonObject.get("name"))){
                                                            continue b;
                                                        }
                                                        //满足一个:返回true，退出循环
                                                        resultVal = true;
                                                        break a;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }else if ("checkResultTime".equals(sourceCode)){
                                //检查结果-时间
                                c:for (Map<String, Object> map : exams) {
                                    String content = "";
                                    if (CommonUtil.isNotEmpty(map.get("repDate"))) {
                                        if (CommonUtil.isNotEmpty(map.get("examDesc"))) {
                                            content += map.get("examDesc") + "。";
                                        }
                                        if (CommonUtil.isNotEmpty(map.get("resultDesc"))) {
                                            content += map.get("resultDesc") + "。";
                                        }
                                        String NLPValue = (String) NLPUtil.parse(nlpUrl, content);
                                        JSONArray jsonArray = JSONArray.parseArray(NLPValue);
                                        if (jsonArray.size() > 0){
                                            a:for (int i = 0;i < jsonArray.size();i ++){
                                                JSONObject jsonObject = jsonArray.getJSONObject(i);
                                                b:for (SdsStandDicMatchParamEntity sdsStandDicMatchParam : dicMatchParamEntities){
                                                    //目前没有排除
                                                    String compareContent = sdsStandDicMatchParam.getCompareContent();
                                                    if (compareContent.contains(",")){
                                                        //eg:皮肤瘙痒#level:加重,day_time:夜间
                                                        //同时满足
                                                        String[] split = compareContent.split(",");
                                                        for (String s : split){
                                                            if (s.contains("#")){
                                                                String[] split1 = s.split("#");
                                                                String name = split1[0];
                                                                String nlpValue = split1[1];
                                                                if (!name.equals(jsonObject.get("name"))){
                                                                    continue b;
                                                                }
                                                                if (nlpValue.contains(":")){
                                                                    String[] split2 = nlpValue.split(":");
                                                                    if (!split2[1].equals(jsonObject.get(split2[0]))){
                                                                        continue b;
                                                                    }
                                                                }
                                                            }else {
                                                                if (s.contains(":")){
                                                                    String[] split1 = s.split(":");
                                                                    if (!split1[1].equals(jsonObject.get(split1[0]))){
                                                                        continue b;
                                                                    }
                                                                }
                                                            }
                                                        }
                                                        //都满足:返回true，退出循环
                                                        resultVal = map.get("repDate");
                                                        break c;
                                                    }else {
                                                        //eg:呼吸困难#level:加重
                                                        if (compareContent.contains("#")){
                                                            String[] split = compareContent.split("#");
                                                            String name = split[0];
                                                            String nlpValue = split[1];
                                                            if (!name.equals(jsonObject.get("name"))){
                                                                continue b;
                                                            }
                                                            if (nlpValue.contains(":")){
                                                                String[] split2 = nlpValue.split(":");
                                                                if (!split2[1].equals(jsonObject.get(split2[0]))){
                                                                    continue b;
                                                                }
                                                            }
                                                            //满足一个:返回true，退出循环
                                                            resultVal = map.get("repDate");
                                                            break c;
                                                        }else {
                                                            //eg:level:加重
                                                            if (compareContent.contains(":")){
                                                                String[] split = compareContent.split(":");
                                                                if (!split[1].equals(jsonObject.get(split[0]))){
                                                                    continue b;
                                                                }
                                                                //满足一个:返回true，退出循环
                                                                resultVal = map.get("repDate");
                                                                break c;
                                                            }else {
                                                                //eg:发热
                                                                if (!compareContent.equals(jsonObject.get("name"))){
                                                                    continue b;
                                                                }
                                                                //满足一个:返回true，退出循环
                                                                resultVal = map.get("repDate");
                                                                break c;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }

                    }
                }
            }
        }
        return resultVal;
    }

    /**
     * 获取病人检验系统-送检记录信息
     * 取值时机 目前支持 入院首次和末次，默认末次
     */
    public Object LisVisit(Long episodeId, Long datasourceId, Integer currentTime, Long dicId, Long valueTime,String orderSql){
        Object resultVal = "";
        if (StringUtils.isEmpty(datasourceId)){
            if (1 == currentTime){
                resultVal = DateUtil.getTime();
            }
        }else {
            String valueTimeSql = getLabVisitValueTimeSql(valueTime);
            SdsStandSourceEntity source = sdsStandSourceMapper.selectById(datasourceId);
            if (!StringUtils.isEmpty(source)){
                String sourceCode = source.getSourceCode();
                if (!StringUtils.isEmpty(dicId)){
                    //查找关联医嘱项
                    Map<String, Object> param = new HashMap<String, Object>();
                    // 查询标准项所有关联医嘱
                    param.put("dicId", dicId);
                    List<Long> labIds = sdsStandDicMatchMapper.selectMatchLabIds(param);
                    List<Map<String, Object>> list = new ArrayList<>();
                    if (!labIds.isEmpty()){
                        list = sdsFunctionMapper.selectLabVisit(episodeId, labIds,valueTimeSql);
                    }
                    for (Map<String, Object> map : list) {
                        if (CommonUtil.isNotEmpty(map.get(sourceCode))) {
                            resultVal = map.get(sourceCode);
                            break;
                        }
                    }
                }else {
                    if ("LabCollNum".equals(sourceCode)){
                        //送检记录数量
                        List<Map<String, Object>> list = sdsFunctionMapper.selectLabVisit(episodeId, null,valueTimeSql);
                        if (null != list && list.size() > 0){
                            resultVal = list.size();
                        }else {
                            resultVal = 0;
                        }
                    }else{
                        List<Map<String, Object>> list = sdsFunctionMapper.selectLabVisit(episodeId, null,valueTimeSql);
                        if(CommonUtil.isEmpty(list)){
                            return resultVal;
                        }
                        resultVal=list.get(0).get(sourceCode);
                        if(CommonUtil.isNotEmpty(list.get(0).get(sourceCode))&&("LabRecTime".equals(sourceCode)||"LabCollTime".equals(sourceCode))){
                            resultVal=list.get(0).get(sourceCode).toString().substring(0,19);
                        }
                    }
                }
            }
        }
        return resultVal;
    }
    private String getLabVisitValueTimeSql(Long valueTime){
        String res="";
        if (CommonUtil.isEmpty(valueTime)) {
            res = "ORDER BY v.rec_date DESC";
        }else {
            DictionaryEntity getTimingDic = dictionaryMapper.selectById(valueTime);
            String getType = getTimingDic.getCode();
            if ("LastInHosp".equals(getType)){
                // 住院末次
                res = "ORDER BY v.rec_date DESC";
            }else if ("InHosp".equals(getType)){
                //入院首次
                res = "ORDER BY v.rec_date ASC";
            }
        }
        return res;
    }


    /**
     * 获取病人检验系统-检验报告信息
     */
    public Object LisReport(Long episodeId, Long datasourceId, Integer currentTime, Long dicId, Long valueTime,String orderSql){
        Object resultVal = "";
        if (StringUtils.isEmpty(datasourceId)){
            if (1 == currentTime){
                resultVal = DateUtil.getTime();
            }
        }else {
            SdsStandSourceEntity source = sdsStandSourceMapper.selectById(datasourceId);
            if (!StringUtils.isEmpty(source)){
                String sourceCode = source.getSourceCode();
                if (!StringUtils.isEmpty(dicId)){
                    //查找关联医嘱项
                    Map<String, Object> param = new HashMap<String, Object>();
                    // 查询标准项所有关联医嘱
                    param.put("dicId", dicId);
                    List<Long> labIds = sdsStandDicMatchMapper.selectMatchOrderIds(param);
                    List<Map<String, Object>> list = new ArrayList<>();
                    if (!labIds.isEmpty()){
                        list = sdsFunctionMapper.selectLabReport(episodeId, null, labIds, null);
                    }
                    for (Map<String, Object> map : list) {
                        if (CommonUtil.isNotEmpty(map.get(sourceCode))) {
                            resultVal = map.get(sourceCode);
                            break;
                        }
                    }
                }
            }
        }
        return resultVal;
    }

    /**
     * 获取病人检验系统-检验结果信息
     */
    public Object LisResult(Long episodeId, Long datasourceId, Integer currentTime, Long dicId, Long valueTime,String orderSql){
        Object resultVal = "";
        if (StringUtils.isEmpty(datasourceId)){
            if (1 == currentTime){
                resultVal = DateUtil.getTime();
            }
        }else {
            SdsStandSourceEntity source = sdsStandSourceMapper.selectById(datasourceId);
            String valueTimeSql = getLabResultValueTimeSql(valueTime);
            if (!StringUtils.isEmpty(source)){
                String sourceCode = source.getSourceCode();
                if (!StringUtils.isEmpty(dicId)){
                    //查找关联检查项目
                    Map<String, Object> param = new HashMap<String, Object>();
                    // 查询标准项所有关联医嘱
                    param.put("dicId", dicId);
                    List<Long> labItemIds = sdsStandDicMatchMapper.selectMatchLabIds(param);
                    List<Map<String, Object>> list = new ArrayList<>();
                    if (!labItemIds.isEmpty()){
                        //list = sdsFunctionMapper.getLabReportList(episodeId, null, labItemIds, null);
                        list = sdsFunctionMapper.getLabReportList(episodeId, null, labItemIds, valueTimeSql);
                    }
                    for (Map<String, Object> map : list) {
                        if (CommonUtil.isNotEmpty(map.get(sourceCode))) {
                            resultVal = map.get(sourceCode);
                            break;
                        }
                    }
                }
            }
        }
        return resultVal;
    }

    private String getLabResultValueTimeSql(Long valueTime){
        String res="";
        if (CommonUtil.isEmpty(valueTime)) {
            res = "ORDER BY n.report_date DESC";
        }else {
            DictionaryEntity getTimingDic = dictionaryMapper.selectById(valueTime);
            String getType = getTimingDic.getCode();
            if ("LastInHosp".equals(getType)){
                // 住院末次
                res = "ORDER BY n.report_date DESC";
            }else if ("InHosp".equals(getType)){
                //入院首次
                res = "ORDER BY n.report_date ASC";
            }
        }
        return res;
    }

    /**
     * 获取病人VTE系统信息
     * todo:与规则库传参不一样，需单独调用
     */
    public Object VTE(Long episodeId, Long datasourceId, Integer currentTime, Long dicId, Long valueTime, Long itemId, Long entityId,String orderSql){
        Object resultVal = "";
        if (StringUtils.isEmpty(datasourceId)){
            if (1 == currentTime){
                resultVal = DateUtil.getTime();
            }
        }else {
            SdsStandSourceEntity source = sdsStandSourceMapper.selectById(datasourceId);
            if (!StringUtils.isEmpty(source)){
                String sourceCode = source.getSourceCode();
                // 获取HIS就诊号
                CdcEpisodeEntity paadm = cdcEpisodeMapper.selectById(episodeId);
                String patientId = paadm.getXcode();
                SdsQcentityEntity qcEntity = QcEntityCache.me().getQcEntityById(entityId);
                String abbrev = qcEntity.getAbbrev();
                if (CommonUtil.equals(abbrev, "AECOPD")) {
                    String subUrl = "/api/getMZFitem?EpisodeID=";
                    resultVal = this.getMZFitem(patientId, itemId, sourceCode,subUrl);
                } else if (CommonUtil.equals(abbrev, "DVT")) {
                    String subUrl = "/api/getWSQitem?EpisodeID=";
                    resultVal = this.getWSQAndZGWitem(patientId, itemId, sourceCode,subUrl);
                } else {
                    String subUrl = "/api/getZGWYFVTEitem?EpisodeID=";
                    resultVal = this.getWSQAndZGWitem(patientId, itemId, sourceCode,subUrl);
                }
            }
        }
        return resultVal;
    }

    /**
     * 获取病人评估/评价信息
     */
    public Object SingleDiseaseEval(Long episodeId, Long datasourceId, Integer currentTime, Long dicId, Long valueTime,String orderSql) {
        Object res = "";
        if (StringUtils.isEmpty(datasourceId)){
            if (1 == currentTime){
                res = DateUtil.getTime();
            }
        }else {
            SdsStandSourceEntity source = sdsStandSourceMapper.selectById(datasourceId);
            if (!StringUtils.isEmpty(source)){
                String sourceCode = source.getSourceCode();
                String dicEntityName = "";
                if (!StringUtils.isEmpty(dicId)){
                    SdsStandDicEntity dicEntity = sdsStandDicMapper.selectById(dicId);
                    dicEntityName = dicEntity.getName();
                }
                String sqlStr = "";
                if(!StringUtils.isEmpty(valueTime)){
                    sqlStr = this.calcGetEvalTiming(valueTime);
                }
                switch (sourceCode){
                    case "Quantity":
                        //数量
                        Integer quantity = sdcBusiEvaluationService.selectAssessmentQuantityNew(episodeId, dicEntityName, sqlStr);
                        return quantity;
                    case "Grade":
                        //等级
                        String grade = sdcBusiEvaluationService.selectAssessmentGradeNew(episodeId, dicEntityName, sqlStr);
                        return grade;
                    case "Score":
                        //分值
                        Float score = sdcBusiEvaluationService.selectAssessmentScoreNew(episodeId, dicEntityName, sqlStr);
                        return  score;
                    case "Time":
                        //时间
                        //com.dhcc.core.framework.util.DateUtil.compareDate
                        String dateTime = sdcBusiEvaluationService.selectAssessmentTimeNew(episodeId, dicEntityName, sqlStr);
                        return dateTime;
                    default:
                        return new String("");
                }
            }

        }

        return res;
    }

    /**
     * 获取病人禁忌症信息
     */
    public Object SingleDiseaseContraindication(Long episodeId, Long datasourceId, Integer currentTime, Long dicId, Long valueTime,String orderSql){
        Object resultVal = "";
        if (StringUtils.isEmpty(datasourceId)){
            if (1 == currentTime){
                resultVal = DateUtil.getTime();
            }
        }else {
            SdsStandSourceEntity source = sdsStandSourceMapper.selectById(datasourceId);
            if (!StringUtils.isEmpty(source)){
                String sourceCode = source.getSourceCode();
                if (!StringUtils.isEmpty(dicId)){
                    SdsStandDicEntity dicEntity = sdsStandDicMapper.selectById(dicId);
                    ContraindicationEntity contraindicationEntity = baseContraindicationService.selectOne(new EntityWrapper<ContraindicationEntity>()
                            .eq("name", dicEntity.getName())
                            .eq("active", 1));
                    if (!StringUtils.isEmpty(contraindicationEntity)){
                        SdcBusiContraindicationEntity sdcBusiContraindicationEntity = sdcBusiContraindicationService.selectOne(new EntityWrapper<SdcBusiContraindicationEntity>()
                                .eq("episode_id", episodeId)
                                .eq("contraindication_id", contraindicationEntity.getId()));
                        if (!StringUtils.isEmpty(sdcBusiContraindicationEntity)) {
                            if ("result".equals(sourceCode)){
                                resultVal = sdcBusiContraindicationEntity.getResult();
                            }
                        }
                    }
                }
            }
        }
        return resultVal;
    }

    /**
     * 获取病人入组信息
     * todo:与规则库传参不一样，需单独调用
     */
    public Object SdsIntheInfo(Long episodeId, Long datasourceId, Integer currentTime, Long dicId, Long valueTime, Long mrListId,String orderSql){
        Object resultVal = "";
        if (StringUtils.isEmpty(datasourceId)){
            if (1 == currentTime){
                resultVal = DateUtil.getTime();
            }
        }else {
            SdsStandSourceEntity source = sdsStandSourceMapper.selectById(datasourceId);
            if (!StringUtils.isEmpty(source)){
                String sourceCode = source.getSourceCode();
                if ("intheReason".equals(sourceCode)) {
                    Wrapper<SdsQcincaseOperlogEntity> wpr = new EntityWrapper<>();
                    wpr.eq("in_case_id", mrListId).eq("oper_state", "I");
                    SdsQcincaseOperlogEntity sdsQcincaseOperlogEntity = sdsQcincaseOperlogService.selectOne(wpr);
                    String reasonStr  = sdsQcincaseOperlogEntity.getOperReason();
                    String[] reasonArr = reasonStr.split(",");
                    List<List<Map<String, Object>>> ressonList = new ArrayList<>();
                    for (String ruleId : reasonArr) {
                        SdsQcentityRuleEntity rule = sdsQcentityRuleService.selectById(ruleId);
                        List<Map<String, Object>> result = new ArrayList<>();
                        Map<String, Object> map = new HashMap<>();
                        map.put("intheReason", rule.getRuleDesc());
                        result.add(map);
                        ressonList.add(result);
                    }
                    resultVal = ressonList;
                }

            }
        }
        return resultVal;
    }

    /**
     * 获取病人护理系统-生命体征信息
     */
    public Object Sign(Long episodeId, Long datasourceId, Integer currentTime, Long dicId, Long valueTime,String orderSql){
        Object resultVal = "";
        if (StringUtils.isEmpty(datasourceId)){
            if (1 == currentTime){
                resultVal = DateUtil.getTime();
            }
        }else {
            SdsStandSourceEntity source = sdsStandSourceMapper.selectById(datasourceId);
            if (!StringUtils.isEmpty(source)){
                String sourceCode = source.getSourceCode();
                Map param = new HashMap<>();
                param.put("episodeId", episodeId);
                param.put("signCode", sourceCode);
                if(!StringUtils.isEmpty(orderSql)){
                    param.put("sqlAsc", orderSql);
                }
                resultVal = sdsFunctionMapper.getSignByCode(param);
            }
        }
        return resultVal;
    }

    /**
     * 获取病人手麻系统信息
     */
    public Object Operate(Long episodeId, Long datasourceId, Integer currentTime, Long dicId, Long valueTime,String orderSql){
        Object resultVal = "";
        if (StringUtils.isEmpty(datasourceId)){
            if (1 == currentTime){
                resultVal = DateUtil.getTime();
            }
        }else {
            SdsStandSourceEntity source = sdsStandSourceMapper.selectById(datasourceId);
            if (!StringUtils.isEmpty(source)){
                String sourceCode = source.getSourceCode();
                List<CdcSurgeryEntity> surgeryEntities = new ArrayList<>();
                if (!StringUtils.isEmpty(dicId)){
                    //配有标准字典根据对照参数取值
                    Map<String, String> mapParam = handleDicMatchParam(dicId, 1);
                    //查询病案编目手术信息
                    surgeryEntities = sdsFunctionMapper.selectSurgeryInfoByParam(episodeId, null, mapParam);
                }else {
                    //只配置数据源
                    surgeryEntities = sdsFunctionMapper.selectSurgeryInfoByParam(episodeId, null, null);
                }
                if (surgeryEntities.size() > 0){
                    if ("Quantity".equals(sourceCode)){
                        if (!StringUtils.isEmpty(valueTime)){
                            List<CdcSurgeryEntity> cdcSurgeryEntities = calcGetOperTiming(episodeId, surgeryEntities, valueTime);
                            resultVal = cdcSurgeryEntities.size();
                        }else {
                            resultVal = surgeryEntities.size();
                        }
                    }else {
                        CdcSurgeryEntity cdcSurgeryEntity = surgeryEntities.get(0);
                        String resultStr = "";
                        if (CommonUtil.equals("startDate", sourceCode)) {
                            resultStr = CommonUtil.isEmpty(cdcSurgeryEntity.getStartDate())?"":DateUtil.getTime(cdcSurgeryEntity.getStartDate());
                        } else if (CommonUtil.equals("endDate", sourceCode)) {
                            resultStr = CommonUtil.isEmpty(cdcSurgeryEntity.getEndDate())?"":DateUtil.getTime(cdcSurgeryEntity.getEndDate());
                        } else if (CommonUtil.equals("LoseBlood", sourceCode)) {
                            resultStr = cdcSurgeryEntity.getBloodLose();
                        } else if (CommonUtil.equals("healType", sourceCode)) {
                            CdcDictionaryEntity cdcDictionaryEntity = cdcDictionaryService.selectById(cdcSurgeryEntity.getBusSurgHealId());
                            if (!StringUtils.isEmpty(cdcDictionaryEntity)) {
                                resultStr = cdcDictionaryEntity.getDescription();
                            }
                        } else if (CommonUtil.equals("GotBlood", sourceCode)) {
                            resultStr = cdcSurgeryEntity.getBloodGet();
                        } else if (CommonUtil.equals("inciLevel", sourceCode)) {
                            CdcDictionaryEntity cdcDictionaryEntity = cdcDictionaryService.selectById(cdcSurgeryEntity.getBusSurgInciId());
                            if (!StringUtils.isEmpty(cdcDictionaryEntity)) {
                                resultStr = cdcDictionaryEntity.getDescription();
                            }
                        } else if (CommonUtil.equals("inciCount", sourceCode)) {
                            resultStr = cdcSurgeryEntity.getInciCount().toString();
                        } else if (CommonUtil.equals("anesType", sourceCode)) {
                            CdcDictionaryEntity cdcDictionaryEntity = cdcDictionaryService.selectById(cdcSurgeryEntity.getBusSurgAnesId());
                            if (!StringUtils.isEmpty(cdcDictionaryEntity)) {
                                resultStr = cdcDictionaryEntity.getDescription();
                            }
                        }
                        resultVal = resultStr;
                    }
                }

            }
        }
        return resultVal;
    }

    private String calcGetEvalTiming(Long valueTime){
        String res = "";
        // 如果没有配置采集时机，默认取最新一条数据
        if (CommonUtil.isEmpty(valueTime)) {
            res = "ORDER BY eval.CREATE_DATE DESC LIMIT 1";
        }else {
            DictionaryEntity getTimingDic = dictionaryMapper.selectById(valueTime);
            String getType = getTimingDic.getCode();
            if ("LastInHosp".equals(getType)){
                // 住院末次
                res = "ORDER BY eval.CREATE_DATE DESC LIMIT 1";
            }else if ("InHosp".equals(getType)){
                //入院首次
                res = "ORDER BY eval.CREATE_DATE ASC LIMIT 1";
            }
        }
        return res;
    }

    private String calcGetExecTiming(Long episodeId, Long valueTime) {
        String sqlStr = "";
        String filterSqlByDate = "AND oe.start_date BETWEEN str_to_date('${sTime}','%Y-%m-%d %H:%i:%s') AND str_to_date('${eTime}', '%Y-%m-%d %H:%i:%s')";
        String filterSqlByAsc = "ORDER BY oe.start_date ${seqType} LIMIT 1";
        String filterSqlByPriority = "AND oe.bus_order_priority_id = ${priorityId} ORDER BY oe.start_date ${seqType} LIMIT 1";
        String seqType = "";
        Long priorityId = 0L;
        Long tmpTime = 0L;
        String fTime = "";
        String tTime = "";
        // 如果没有配置采集时机，默认入院首次
        if (CommonUtil.isEmpty(valueTime)) {
            return "ORDER BY oe.start_date ASC LIMIT 1";
        }
        // 获取采集时间描述
        DictionaryEntity getTimingDic = dictionaryMapper.selectById(valueTime);
        String getType = getTimingDic.getCode();
        // 如果采集时机包含手术，则先取手术开始、结束时间
        if (getType.contains("Oper")) {
            Wrapper<CdcSurgeryEntity> operWpr = new EntityWrapper<>();
            operWpr.eq("episode_id", episodeId).eq("is_active", 1).orderBy("start_date");
            List<CdcSurgeryEntity> operList = cdcSurgeryMapper.selectList(operWpr);
            if (operList.size() == 0) {
                return "";
            }
            // 只取首次手术
            Date startDate = DateUtil.parse("1900-01-01 00:00:00");
            Date endDate = DateUtil.parse("1900-01-01 00:00:00");
            switch (getType) {
                case "BfOper":
                    for (CdcSurgeryEntity oper : operList) {
                        if (oper.getStartDate()!=null||oper.getEndDate()!=null) {
                            startDate = oper.getStartDate();
                            break;
                        }
                    }
                    // 术前，默认手术前0.5-1小时
                    tmpTime = startDate.getTime();
                    fTime = DateUtil.getTime(new Date(tmpTime - 3600 * 1000));
                    tTime = DateUtil.getTime(new Date(tmpTime - 1800 * 1000));
                    sqlStr = filterSqlByDate;
                    break;
                case "InOper":
                    for (CdcSurgeryEntity oper : operList) {
                        if (oper.getStartDate()!=null&&oper.getEndDate()!=null) {
                            startDate = oper.getStartDate();
                            endDate = oper.getEndDate();
                            break;
                        }
                    }
                    // 术中
                    fTime = DateUtil.getTime(startDate);
                    tTime = DateUtil.getTime(endDate);
                    sqlStr = filterSqlByDate;
                    break;
                case "AfOper":
                    for (CdcSurgeryEntity oper : operList) {
                        if (oper.getEndDate()!=null) {
                            endDate = oper.getEndDate();
                            break;
                        }
                    }
                    // 术后，默认手术后72小时
                    if(CommonUtil.isEmpty(endDate)){
                        break;
                    }
                    tmpTime = endDate.getTime();
                    fTime = DateUtil.getTime(endDate);
                    tTime = DateUtil.getTime(new Date(tmpTime + 3 * 24 * 3600 * 1000));
                    sqlStr = filterSqlByDate;
                    break;
                case "AllOper":
                    for (CdcSurgeryEntity oper : operList) {
                        if (oper.getStartDate()!=null||oper.getEndDate()!=null) {
                            startDate = oper.getStartDate();
                            endDate = oper.getEndDate();
                            break;
                        }
                    }
                    //围术期
                    tmpTime = startDate.getTime();
                    fTime = DateUtil.getTime(new Date(tmpTime - 3600 * 1000));
                    tmpTime = endDate.getTime();
                    tTime = DateUtil.getTime(new Date(tmpTime + 3 * 24 * 3600 * 1000));
                    sqlStr = filterSqlByDate;
                    break;
            }
        } else {
            // 获取就诊时间
            CdcEpisodeEntity admObj = cdcEpisodeMapper.selectById(episodeId);
            Date admDate = admObj.getAdmDate();
            Date dishDate = admObj.getDishDate();
            switch (getType) {
                case "Emergency":
                    // 急诊
                    break;
                case "LastInHosp":
                    // 住院末次
                    seqType = "DESC";
                    sqlStr = filterSqlByAsc;
                    break;
                case "EMR-Inhos24":
                    // 急诊/入院24小时
                    tmpTime = admDate.getTime();
                    fTime = DateUtil.getTime(admDate);
                    tTime = DateUtil.getTime(new Date(tmpTime + 24 * 3600 * 1000));
                    sqlStr = filterSqlByDate;
                    break;
                case "DishHosMedi":
                    // 出院带药 bus_order_priority:OUT
                    CdcDictionaryEntity cdcDictionaryEntity = cdcDictionaryService.queryByTypeCodeAndCode("OrdData", "bus_order_priority", "OUT");
                    if (!StringUtils.isEmpty(cdcDictionaryEntity)) {
                        seqType = "ASC";
                        priorityId = cdcDictionaryEntity.getId();
                        sqlStr = filterSqlByPriority;
                    }
                    break;
                case "LongOrder":
                    // 长期医嘱 bus_order_priority:S
                    CdcDictionaryEntity cdcDictionaryEntity1 = cdcDictionaryService.queryByTypeCodeAndCode("OrdData", "bus_order_priority", "S");
                    if (!StringUtils.isEmpty(cdcDictionaryEntity1)) {
                        seqType = "ASC";
                        priorityId = cdcDictionaryEntity1.getId();
                        sqlStr = filterSqlByPriority;
                    }
                     break;

                case "DurHosp":
                    // 住院期间 医嘱日期范围为住院期间
                    fTime = DateUtil.getTime(admDate);
                    tTime = DateUtil.getTime(dishDate);
                    sqlStr = filterSqlByDate;
                    break;
                default:
                    // 默认入院首次
                    seqType = "ASC";
                    sqlStr = filterSqlByAsc;
                    break;
            }
        }
        Map<String, Object> map = new HashMap<>();
        map.put("sTime", fTime);
        map.put("eTime", tTime);
        map.put("seqType", seqType);
        map.put("priorityId", priorityId);
        StrSubstitutor strSubstitutor = new StrSubstitutor(map);
        sqlStr = strSubstitutor.replace(sqlStr);
        return sqlStr;
    }

    private List<CdcSurgeryEntity> calcGetOperTiming(Long episodeId, List<CdcSurgeryEntity> surgeryEntities, Long valueTime) {
        // 获取采集时间描述
        DictionaryEntity getTimingDic = dictionaryMapper.selectById(valueTime);
        String getType = getTimingDic.getCode();
        Date startDate = DateUtil.parse("1900-01-01 00:00:00");
        Date endDate = DateUtil.parse("1900-01-01 00:00:00");
        Long tmpTime = 0L;
        String fTime = "";
        String tTime = "";
        List<CdcSurgeryEntity> operList = new ArrayList<>();
        if (getType.contains("Oper")) {
            switch (getType) {
                case "BfOper":
                    for (CdcSurgeryEntity oper : surgeryEntities) {
                        if (oper.getStartDate() != null || oper.getEndDate() != null) {
                            startDate = oper.getStartDate();
                            break;
                        }
                    }
                    // 术前
                    operList = cdcSurgeryMapper.selectByTime(episodeId, DateUtil.getTime(startDate), null, getType);
                    break;
                case "InOper":
                    for (CdcSurgeryEntity oper : surgeryEntities) {
                        if (oper.getStartDate() != null && oper.getEndDate() != null) {
                            startDate = oper.getStartDate();
                            endDate = oper.getEndDate();
                            break;
                        }
                    }
                    // 术中
                    fTime = DateUtil.getTime(startDate);
                    tTime = DateUtil.getTime(endDate);
                    operList = cdcSurgeryMapper.selectByTime(episodeId, fTime, tTime, getType);
                    break;
                case "AfOper":
                    for (CdcSurgeryEntity oper : surgeryEntities) {
                        if (oper.getStartDate() != null || oper.getEndDate() != null) {
                            endDate = oper.getEndDate();
                            break;
                        }
                    }
                    // 术后
                    fTime = DateUtil.getTime(startDate);
                    tTime = DateUtil.getTime(endDate);
                    operList = cdcSurgeryMapper.selectByTime(episodeId, fTime, tTime, getType);
                    break;
            }
        }
        return operList;
    }

    //type:1-手术；2-诊断;3-科室
    private Map<String, String> handleDicMatchParam(Long dicEntityId, Integer type) {
        Map<String, String> res = new HashMap<>();

        //排除关键字sql
        String kfilterTxt = "";
        //排除通用名sql
        String cfilterTxt = "";
        //同时满足关键字sql
        String kwordAndTxt = "";
        //同时满足通用名sql
        String cwordAndTxt = "";
        //满足一个关键字sql
        String kwordOrTxt = "";
        //满足一个通用名sql
        String cwordOrTxt = "";

        List<SdsStandDicMatchParamEntity> dicMatchParamEntities = sdsStandDicMatchParamMapper.selectList(new EntityWrapper<SdsStandDicMatchParamEntity>()
                .eq("dic_id", dicEntityId));
        for (SdsStandDicMatchParamEntity sdsStandDicMatchParam : dicMatchParamEntities){
            if ("O".equals(sdsStandDicMatchParam.getFilterType())){
                //O-排除 排除只处理对照内容只有一个的情况（包含&未考虑
                if ("K".equals(sdsStandDicMatchParam.getCompareType())){
                    kfilterTxt = kfilterTxt + "|" + sdsStandDicMatchParam.getCompareContent();
                }else if ("C".equals(sdsStandDicMatchParam.getCompareType())){
                    cfilterTxt = cfilterTxt + "|" + sdsStandDicMatchParam.getCompareContent();
                }
            }else if ("I".equals(sdsStandDicMatchParam.getFilterType())){
                if ("K".equals(sdsStandDicMatchParam.getCompareType())){
                    if (sdsStandDicMatchParam.getCompareContent().contains("&")){
                        String[] split1 = sdsStandDicMatchParam.getCompareContent().split("&");
                        for (int i = 0; i <= split1.length - 1; i++) {
                            if (i == 0) {
                                kwordAndTxt = kwordAndTxt + " or description like '%" + split1[0] + "%'";
                            } else {
                                kwordAndTxt = kwordAndTxt + " and description like '%" + split1[i] + "%'";
                            }
                        }
                    }else {
                        kwordOrTxt = kwordOrTxt + "|" +sdsStandDicMatchParam.getCompareContent();
                    }
                }else if ("C".equals(sdsStandDicMatchParam.getCompareType())){
                    if (sdsStandDicMatchParam.getCompareContent().contains("&")){
                        String[] split2 = sdsStandDicMatchParam.getCompareContent().split("&");
                        for (int i = 0; i <= split2.length - 1; i++) {
                            if (i == 0) {
                                cwordAndTxt = cwordAndTxt + " or drug_common_name like '%" + split2[0] + "%'";
                            } else {
                                cwordAndTxt = cwordAndTxt + " and drug_common_name like '%" + split2[i] + "%'";
                            }
                        }
                    }else {
                        cwordOrTxt = cwordOrTxt + "|" +sdsStandDicMatchParam.getCompareContent();
                    }
                }
            }
        }

        if ("" != kwordOrTxt) {
            kwordOrTxt = kwordOrTxt.substring(1, kwordOrTxt.length());
        }
        if ("" != kwordAndTxt){
            if (1 == type){
                kwordAndTxt = kwordAndTxt.replace("description", "code");
            }
            if (2 == type){
                kwordAndTxt = kwordAndTxt.replace("description", "icd10");
            }
            if (3 == type){
                kwordAndTxt = kwordAndTxt.replace("description", "adm_loc_desc");
            }
        }
        if ("" != cwordOrTxt) {
            cwordOrTxt = cwordOrTxt.substring(1, cwordOrTxt.length());
        }
        if ("" != kfilterTxt) {
            kfilterTxt = kfilterTxt.substring(1, kfilterTxt.length());
        }
        if ("" != cfilterTxt) {
            cfilterTxt = cfilterTxt.substring(1, cfilterTxt.length());
        }
        if ("" != kwordAndTxt && ("" == kwordOrTxt || "" == cwordOrTxt)) {
            kwordAndTxt = kwordAndTxt.replaceFirst("or", "and");
        }
        if ("" != cwordAndTxt && ("" == kwordOrTxt || "" == cwordOrTxt)) {
            cwordAndTxt = cwordAndTxt.replaceFirst("or", "and");
        }

        res.put("kfilterTxt", kfilterTxt);
        res.put("cfilterTxt", cfilterTxt);
        res.put("kwordAndTxt", kwordAndTxt);
        res.put("cwordAndTxt", cwordAndTxt);
        res.put("kwordOrTxt", kwordOrTxt);
        res.put("cwordOrTxt", cwordOrTxt);

        return res;
    }

    private Map<String, String> handleLocMatchParam(Long dicEntityId){
        Map<String, String> res = new HashMap<>();
        //排除的字符串
        String filterTxt = "";
        //满足的字符串
        String wordOrTxt = "";
        List<SdsStandDicMatchParamEntity> dicMatchParamEntities = sdsStandDicMatchParamMapper.selectList(new EntityWrapper<SdsStandDicMatchParamEntity>()
                .eq("dic_id", dicEntityId));
        for (SdsStandDicMatchParamEntity sdsStandDicMatchParam : dicMatchParamEntities){
            if ("O".equals(sdsStandDicMatchParam.getFilterType())){
                filterTxt = filterTxt + "|" + sdsStandDicMatchParam.getCompareContent();
            }else if ("I".equals(sdsStandDicMatchParam.getFilterType())){
                wordOrTxt = wordOrTxt + "|" +sdsStandDicMatchParam.getCompareContent();
            }
        }

        res.put("filterTxt", filterTxt);
        res.put("wordOrTxt", wordOrTxt);
        return res;
    }
    /**
     * 根据就诊号获取【慢阻肺】相关VTE结果
     *
     * @param episodeId
     * @return
     */
    private String getMZFitem(String episodeId, Long itemId, String sourceCode, String subUrl) {
        String result = "";
        JSONObject obj = this.vteHttpGet(subUrl, episodeId);
        int status = obj.getInteger("code");
        if (status == 200) {
            Object strObj = obj.getJSONObject("data").get(sourceCode);
            if (CommonUtil.equals(sourceCode, "isHighRisk")) {
                if ((int) strObj == 1) {
                    result = "y";
                } else {
                    result = "n";
                }
            } else if (CommonUtil.equals(sourceCode, "treatList")) {
                if (CommonUtil.isNotEmpty(strObj)) {
                    JSONArray array = JSONArray.parseArray(String.valueOf(strObj));
                    // 获取值域字典
//                    Wrapper<SdsQcfitemDicEntity> itemDicWpr = new EntityWrapper<>();
//                    itemDicWpr.eq("form_item_id", itemId).eq("is_active", 1);
//                    List<SdsQcfitemDicEntity> itemDicList = sdsQcfitemDicMapper.selectList(itemDicWpr);
                    List<SdsQcfitemDicEntity> itemDicList = FormItemDicCache.me().getFormItemDicList(itemId);
                    a:
                    for (SdsQcfitemDicEntity dic : itemDicList) {
                        for (int i = 0; i < array.size(); i++) {
                            /*if (CommonUtil.isNotEmpty(dic.getKeyword())) {
                                if (dic.getKeyword().equals(array.getString(i))) {
                                    result += dic.getCode() + ",";
                                    continue a;
                                }
                            } else {
                                if (dic.getDesc().contains(array.getString(i))) {
                                    result += dic.getCode() + ",";
                                    continue a;
                                }
                            }*/
                            if (dic.getDesc().contains(array.getString(i))) {
                                result += dic.getCode() + ",";
                                continue a;
                            }
                        }
                    }
                }
            } else if (CommonUtil.equals(sourceCode, "otherTreat")) {
                if (CommonUtil.isNotEmpty(strObj)) {
                    result = String.valueOf(strObj);
                }
            }
        }
        return result;
    }

    /**
     * 根据就诊号获取【围术期预深静脉血栓】相关VTE结果 或 【中高危风险患者预防静脉血栓】相关VTE结果
     *
     * @param episodeId
     * @return
     */
    private String getWSQAndZGWitem(String episodeId, Long itemId, String sourceCode, String subUrl) {
        String result = "";
        JSONObject obj = this.vteHttpGet(subUrl, episodeId);
        int status = obj.getInteger("code");
        if (status == 200) {
            Object strObj = obj.getJSONObject("data").get(sourceCode);
            if (CommonUtil.isNotEmpty(strObj)) {
                if (CommonUtil.equals(sourceCode, "score")) {
                    result = String.valueOf(strObj);
                } else {
                    // 获取值域字典
//                    Wrapper<SdsQcfitemDicEntity> itemDicWpr = new EntityWrapper<>();
//                    itemDicWpr.eq("form_item_id", itemId).eq("is_active", 1);
//                    List<SdsQcfitemDicEntity> itemDicList = sdsQcfitemDicMapper.selectList(itemDicWpr);
                    List<SdsQcfitemDicEntity> itemDicList = FormItemDicCache.me().getFormItemDicList(itemId);
                    for (SdsQcfitemDicEntity dic : itemDicList) {
                       /* if (CommonUtil.isNotEmpty(dic.getKeyword())) {
                            if (dic.getKeyword().equals(strObj.toString())) {
                                result = dic.getCode();
                                break;
                            }
                        } else {
                            if (dic.getDesc().contains(strObj.toString())) {
                                result = dic.getCode();
                                break;
                            }
                        }*/
                        if (dic.getDesc().contains(strObj.toString())) {
                            result = dic.getCode();
                            break;
                        }
                    }
                }
            }
        }
        return result;
    }

    private JSONObject vteHttpGet(String subUrl, String episodeId) {
        JSONObject obj = new JSONObject();
        // VTE服务url
        String vteServerUrl = CdcConfigCache.me().getValueByKey("SDS","VTEServer");
        // 创建httpClient对象
        CloseableHttpClient client = HttpClients.createDefault();
        // 创建请求方法的实例，并指定请求URL
        String url = vteServerUrl + subUrl + episodeId;
        HttpGet get = new HttpGet(url);
        // 调用execute,返回response
        CloseableHttpResponse response = null;
        try {
            response = client.execute(get);
            String str = EntityUtils.toString(response.getEntity());
            obj = JSONObject.parseObject(str);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (client != null) {
                    client.close();
                }
                if (response != null) {
                    response.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return obj;
    }



}
